package cn.edu.wfit.modules.learn.service.impl.competitionmanagement;

import java.util.List;

import cn.edu.wfit.common.core.utils.DateUtils;
import cn.edu.wfit.modules.learn.domain.WfitCompetitionAward;
import cn.edu.wfit.modules.learn.domain.WfitCompetitionConfig;
import cn.edu.wfit.modules.learn.mapper.competitionmanagement.WfitCompetitionAwardMapper;
import cn.edu.wfit.modules.learn.mapper.competitionmanagement.WfitCompetitionConfigMapper;
import cn.edu.wfit.modules.learn.service.competitionmanagement.IWfitCompetitionAwardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 竞赛证书认证Service业务层处理
 *
 * @author ruoyi
 * @date 2025-07-28
 */
@Service
public class WfitCompetitionAwardServiceImpl implements IWfitCompetitionAwardService {
    @Autowired
    private WfitCompetitionAwardMapper wfitCompetitionAwardMapper;

    @Autowired
    private WfitCompetitionConfigMapper wfitCompetitionConfigMapper;



    /**
     * 查询竞赛证书认证
     *
     * @param id 竞赛证书认证主键
     * @return 竞赛证书认证
     */
    @Override
    public WfitCompetitionAward selectWfitCompetitionAwardById(Long id) {
        return wfitCompetitionAwardMapper.selectWfitCompetitionAwardById(id);
    }

    /**
     * 查询竞赛证书认证列表
     *
     * @param wfitCompetitionAward 竞赛证书认证
     * @return 竞赛证书认证
     */
    @Override
    public List<WfitCompetitionAward> selectWfitCompetitionAwardList(WfitCompetitionAward wfitCompetitionAward) {
        return wfitCompetitionAwardMapper.selectWfitCompetitionAwardList(wfitCompetitionAward);
    }

    /**
     * 新增竞赛证书认证
     *
     * @param wfitCompetitionAward 竞赛证书认证
     * @return 结果
     */
    @Override
    public int insertWfitCompetitionAward(WfitCompetitionAward wfitCompetitionAward) {

        /*证书认定表自动赋分*/
        Long competitionId = wfitCompetitionAward.getCompetitionId();
        String awardGrade = wfitCompetitionAward.getAwardGrade();
        String awardLevel = wfitCompetitionAward.getAwardLevel();
        WfitCompetitionConfig config = new WfitCompetitionConfig();
        config.setCompetitionId(competitionId);
        config.setAwardGrade(awardGrade);
        config.setAwardLevel(awardLevel);

        List<WfitCompetitionConfig> getScore = wfitCompetitionConfigMapper.selectWfitCompetitionConfigList(config);
        if(!getScore.isEmpty()){
            wfitCompetitionAward.setScore(getScore.get(0).getScoreValue());
        }
        wfitCompetitionAward.setCreateTime(DateUtils.getNowDate());
        return wfitCompetitionAwardMapper.insertWfitCompetitionAward(wfitCompetitionAward);
    }

    /**
     * 修改竞赛证书认证
     *
     * @param wfitCompetitionAward 竞赛证书认证
     * @return 结果
     */
    @Override
    public int updateWfitCompetitionAward(WfitCompetitionAward wfitCompetitionAward) {
        wfitCompetitionAward.setCreateTime(DateUtils.getNowDate());
        return wfitCompetitionAwardMapper.updateWfitCompetitionAward(wfitCompetitionAward);
    }

    /**
     * 批量删除竞赛证书认证
     *
     * @param ids 需要删除的竞赛证书认证主键
     * @return 结果
     */
    @Override
    public int deleteWfitCompetitionAwardByIds(Long[] ids) {
        return wfitCompetitionAwardMapper.deleteWfitCompetitionAwardByIds(ids);
    }

    /**
     * 删除竞赛证书认证信息
     *
     * @param id 竞赛证书认证主键
     * @return 结果
     */
    @Override
    public int deleteWfitCompetitionAwardById(Long id) {
        return wfitCompetitionAwardMapper.deleteWfitCompetitionAwardById(id);
    }
}
